package cn.newgrand.netcall.integration.setting;

import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

import org.jivesoftware.resource.Res;
import org.jivesoftware.spark.component.VerticalFlowLayout;
import org.jivesoftware.spark.util.ResourceUtils;

/**
 * @author SidneyRen E-mail:SidneyRen@hotmail.com
 * @version create time：2010-12-30 下午07:01:45
 * 类说明
 */
public class SettingPanel extends JPanel {
	final JCheckBox loginURLIntranetBox = new JCheckBox();
    final JTextField loginURLIntranetField = new JTextField();

    final JCheckBox loginURLInternetBox = new JCheckBox();
    final JTextField loginURLInternetField = new JTextField();
    
    private JLabel awayTimeLabel = new JLabel();
    private JTextField awayTimeField = new JTextField(4);
    private JLabel offlineTimeLabel = new JLabel();
    private JTextField offlineTimeField = new JTextField(4);
    private JCheckBox isConvertSMS = new JCheckBox();
    
    private JPanel loginSettingPanel = new JPanel();
    private JPanel configSendSMSInterval = new JPanel();
    
    public SettingPanel(){
    	setLayout(new VerticalFlowLayout());
    	loginSettingPanel.setBorder(BorderFactory.createTitledBorder("登入设置"));
    	loginSettingPanel.setLayout(new GridBagLayout());
    	configSendSMSInterval.setBorder(BorderFactory.createTitledBorder("配置离开离线转短信时间间隔"));
    	configSendSMSInterval.setLayout(new GridBagLayout());
    	//setBorder(BorderFactory.createTitledBorder("登入设置"));
	
	    // Add ResourceUtils
	    ResourceUtils.resButton(loginURLIntranetBox, "内网地址");
	    ResourceUtils.resButton(loginURLInternetBox, "外网地址");
	    
	    ResourceUtils.resLabel(awayTimeLabel, "离开时间 (分钟):");
	    ResourceUtils.resLabel(offlineTimeLabel, "离线时间 (分钟):");
	    ResourceUtils.resButton(isConvertSMS, "离线离开消息自动转短信");
	    
//	    loginURLInternetField.setPreferredSize(preferredSize)
	    
	    loginSettingPanel.add(loginURLIntranetBox, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.NORTH, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
	    loginSettingPanel.add(loginURLIntranetField, new GridBagConstraints(1, 0, 1, 1, 1.0, 0.0, GridBagConstraints.NORTH, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5), 0, 0));

	    loginSettingPanel.add(loginURLInternetBox, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.NORTH, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
	    loginSettingPanel.add(loginURLInternetField, new GridBagConstraints(1, 1, 1, 1, 1.0, 1.0, GridBagConstraints.NORTH, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5), 0, 0));

	    configSendSMSInterval.add(awayTimeLabel, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
	    configSendSMSInterval.add(awayTimeField, new GridBagConstraints(1, 0, 1, 1, 1.0, 1.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 50, 0));
	    configSendSMSInterval.add(offlineTimeLabel, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
	    configSendSMSInterval.add(offlineTimeField, new GridBagConstraints(1, 1, 1, 1, 1.0, 1.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 50, 0));
	    
	    add(loginSettingPanel);
	    add(configSendSMSInterval);
        loginURLIntranetBox.addActionListener(new ActionListener() {
        	@Override
        	public void actionPerformed(ActionEvent e) {
        		if(loginURLIntranetBox.isSelected()){
        			loginURLInternetBox.setSelected(false);
        		}else{
        			loginURLInternetBox.setSelected(true);
        		}
        	}
        });
        loginURLInternetBox.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent e) {
				if(loginURLInternetBox.isSelected()){
					loginURLIntranetBox.setSelected(false);
				}else{
					loginURLIntranetBox.setSelected(true);
				}
			}
		});
    }
        public String getLoginURLIntranet() {
    		return loginURLIntranetField.getText();
    	}

    	public void setLoginURLIntranet(String loginURLIntranet) {
    		loginURLIntranetField.setText(loginURLIntranet);
    	}

    	public String getLoginURLInternet() {
    		return loginURLInternetField.getText();
    	}

    	public void setLoginURLInternet(String loginURLInternet) {
    		loginURLInternetField.setText(loginURLInternet);
    	}

    	public boolean isSelectedIntranet() {
    		return loginURLIntranetBox.isSelected();
    	}

    	public void setSelectedIntranet(boolean selectedIntranet) {
    		loginURLIntranetBox.setSelected(selectedIntranet);
    	}
    	
    	public boolean isSelectedInternet() {
    		return loginURLInternetBox.isSelected();
    	}

    	public void setSelectedInternet(boolean selectedInternet) {
    		loginURLInternetBox.setSelected(selectedInternet);
    	}
    	
    	public void setAwayTime(String time){
    		awayTimeField.setText(time);
    	}
    	
    	public String getAwayTime(){
    		return awayTimeField.getText();
    	}
    	
    	public void setOfflineTime(String time){
    		offlineTimeField.setText(time);
    	}
    	
    	public String getOfflineTime(){
    		return offlineTimeField.getText();
    	}
}
